package com.power.project.model.vo;

import com.power.project.model.dto.UserDTO;
import com.power.project.model.dto.UserDepartDTO;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.util.Assert;

import java.util.List;

/**
 * @Author mrzhao
 * @CreateDate 2024/6/26 10:17
 * @Desc TODO
 * @Version 1.0
 */
@EqualsAndHashCode(callSuper = true)
@AllArgsConstructor
@NoArgsConstructor
@Data
public class DepartUserVO extends UserBaseVO {

    @ApiModelProperty(value = "是否是当前部门的负责人 0:否 1:是")
    private Boolean isLeader;

    public DepartUserVO(UserDTO dto) {
        super(dto);
    }

    /**
     * @param userDeparts 用户所属的部门列表
     * @param departId    当前选择的目标部门
     */
    public void setIsLeader(List<UserDepartDTO> userDeparts, String departId) {
        Assert.notNull(departId, "目标部门id不能为空");
        userDeparts.stream()
                .filter(t -> t.getDepartId().equals(departId))
                .findFirst()
                .ifPresent(t -> this.isLeader = Integer.valueOf(1).equals(t.getIsLeader()));
    }
}
